<?php

namespace App\Http\Controllers\Index;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Controllers\Index\Base;
use Illuminate\Support\Facades\DB;
use App\Serves\GoodsServe;

class Goods extends Base
{
    //
    public function lists(Request $request, $catid){
//        echo $aa;
        if(!is_numeric($catid)){
           return redirect('/');
        }
        //列表数据
        $field = ['sku_id','name','stock','price','main_image'];
        $goods = GoodsServe::getGoodsByCategoryid($catid,$field);
        $categorys = $this->getTreeCategory();
        return view('index/lists')->with([
            'categorys'=>$categorys,
            'goods'=>$goods,
        ]);


    }

    public function details($id){
//        $param = $request->all();
//        $skuid = $param['id'];
//        GoodsServe::
        if(empty($id) || is_numeric($id)){
            redirect('/');
        }

        $goods = GoodsServe::getDetails($id);
//        var_dump($goods);
        return view('index/details')->with([
            'goods'=>$goods
        ]);


    }


}
